package NGUYENLAMSON.ARRAY;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Baitoan3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 1 Khai bao va khoi tao mang 1 chieu doi tuong
		List<Student>lisStudent= new ArrayList<Student>();
		//2 Khai bao va khoi  tao doi doi tuong sinh vien 
		Student SV01=new Student();
		SV01.setRollno(1);
		SV01.setFullname("Nguyen Van A");
		SV01.setMark(10);
		Student SV02=new Student();
		SV02.setRollno(2);
		SV02.setFullname("Nguyen Van B");
		SV02.setMark(7);
		Student SV03=new Student();
		SV03.setRollno(3);
		SV03.setFullname("Nguyen Van C");
		SV03.setMark(8);
		//3 Dua cac doi tuong vao mang 
		lisStudent.add(SV01);
		lisStudent.add(SV02);
		lisStudent.add(SV03);
		//4 Hien thi thong tin cac sinh vien 
		for(int i=0;i<lisStudent.size();i++){
			System.out.println("-----"+lisStudent.get(i).getFullname());
			System.out.println("RollNo     "+lisStudent.get(i).getRollno());
			System.out.println("FullName   "+lisStudent.get(i).getFullname());
			System.out.println("RollNo"    +lisStudent.get(i).getMark());
		}
		// 5 Sap xep theo diem 
		Collections.sort(lisStudent,new Comparator<Student>() {
			@Override
			/*return -1 : giam dan 
			 * return 1 : tang dan 
			 * return 0 : ko can phai sap xep 
			 */
			public int compare(Student obj01, Student obj02) {
				if( obj01.getMark()< obj02.getMark()){
					return -1;
				}else if (obj01.getMark()>obj02.getMark()){
					return 1;
				}else
				return 0;
			}
		});
		for(int i=0;i<lisStudent.size();i++){
			System.out.println("-----"+lisStudent.get(i).getFullname());
			System.out.println("RollNo     "+lisStudent.get(i).getRollno());
			System.out.println("FullName   "+lisStudent.get(i).getFullname());
			System.out.println("RollNo"    +lisStudent.get(i).getMark());
		}
		//5.1 Sap xep theo ten 
		Collections.sort(lisStudent,new Comparator<Student>(){
			@Override
			/*return -1 : giam dan 
			 * return 1 : tang dan 
			 * return 0 : ko can phai sap xep 
			 */
			public int compare(Student obj01, Student obj02){
				return obj02.getFullname().compareTo(obj01.getFullname());
			}
		});
		for(int i=0;i<lisStudent.size();i++){
			System.out.println("-----"+lisStudent.get(i).getFullname());
			System.out.println("RollNo     "+lisStudent.get(i).getRollno());
			System.out.println("FullName   "+lisStudent.get(i).getFullname());
			System.out.println("RollNo"    +lisStudent.get(i).getMark());
		}
	}
	}

